import 'package:get/get_state_manager/src/simple/get_controllers.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:xvideos/hj_model/video_model.dart';
import 'package:xvideos/hj_utils/api_service/mine_service.dart';

import '../../home_business/search_page/search_result_page/search_video_result_page.dart';

class UserWorkListLogic extends GetxController {

  final int uid;
  final SearchType newsType;

  UserWorkListLogic(this.uid, this.newsType,);

  bool isLoading = true;
  int page = 1;
  List<VideoModel> dataSource = [];
  RefreshController? refreshController;


  @override
  void onInit() {
    fetchPageData();
    super.onInit();
  }

  fetchPageData({bool isRefresh = true, bool needLoading = false}) async {
    if (isRefresh) {
      page = 1;
    }
    if (needLoading) {
      isLoading = true;
      update();
    }
    final result = await MineService.fetchMyPublishes(page: page, uid:uid, newsType: newsType.realm);
    isLoading = false;
    if (isRefresh) {
      refreshController?.refreshCompleted();
      dataSource.clear();
    }
    if (result.hasNext ?? false) {
      refreshController?.loadComplete();
    } else {
      refreshController?.loadNoData();
    }
    dataSource.addAll(result.list ?? []);
    page += 1;
    update();
  }


}
